//
// Copyright (c) 2024 BPer
//
#ifndef __BPerH264EncoderMeta__
#define __BPerH264EncoderMeta__

#include <bperavutil/video/BPerVideoEncoderMeta.h>
#include <bperutil/BPerAvInfoType.h>
#include <bperutil/sys/BPerLoadLib.h>
#include <x264.h>

#if BPer_OS_ANDROID
#define BPer_X264_So 0
#else
#define BPer_X264_So 1
#endif


class BPerH264EncoderMeta:public BPerVideoEncoderMeta{
public:
	BPerH264EncoderMeta();
	~BPerH264EncoderMeta();
	void bPer_initVmd(BPerVideoMeta *p_vmd, BPerVideoInfo *p_config, BPerVideoEncInfo *penc);
private:
	void bPer_getH264Config(uint8_t *p_configBuf, int32_t *p_configLen,
			BPerVideoInfo *p_config);

	void bPer_getSpsPps(BPerH2645Conf *p264, BPerVideoInfo *config, BPerVideoEncInfo *penc);
#if BPer_X264_So
	BPerLoadLib m_lib;
	void loadLib();
	void unloadLib();
	void (*bPer_x264_param_default)(x264_param_t*);
	int32_t    (* bPer_x264_param_default_preset)( x264_param_t *, const char *preset, const char *tune );
	int32_t (*bPer_x264_param_apply_profile)(x264_param_t*, const char *profile);
	int32_t (*bPer_x264_picture_alloc)(x264_picture_t *pic, int32_t i_csp, int32_t i_width,	int32_t i_height);
	int32_t (*bPer_x264_encoder_headers)(x264_t*, x264_nal_t **pp_nal, int32_t *pi_nal);
	void (*bPer_x264_picture_clean)(x264_picture_t *pic);
	void (*bPer_x264_encoder_close)(x264_t*);
	x264_t* (*bPer_x264_encoder_open)(x264_param_t*);
#else
	#define bPer_x264_param_default x264_param_default
	#define bPer_x264_param_default_preset x264_param_default_preset
	#define bPer_x264_param_apply_profile x264_param_apply_profile
	#define bPer_x264_picture_alloc x264_picture_alloc
	#define bPer_x264_encoder_encode x264_encoder_encode
	#define bPer_x264_picture_clean x264_picture_clean
	#define bPer_x264_encoder_close x264_encoder_close
	#define bPer_x264_encoder_open x264_encoder_open
	#define bPer_x264_encoder_headers x264_encoder_headers
#endif
};

#endif
